package vashion.azeroth.core.biz;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import lombok.Data;
import vashion.azeroth.core.activity.GlobalActivityExtendInfoDO;

import java.util.Map;

/**
 * 好物的活动位对象
 * Created by liuhe on 15/10/12.
 */
@Data
public class BannerVO {

    /**
     * 图片
     */
    private String image;

    /**
     * 活动描述
     */
    private String title;

    /**
     * 活动跳转链接
     */
    private String url;

    public static BannerVO buildByActivity(GlobalActivityExtendInfoDO globalActivityExtendInfoDO) {
        BannerVO bannerVO = new BannerVO();
        Map<String, String> jsonMap = JSON.parseObject(globalActivityExtendInfoDO.getContents(), new TypeReference<Map<String, String>>() {
        });
        if (!jsonMap.containsKey("link") || !jsonMap.containsKey("img")) {
            return null;
        }
        bannerVO.setUrl(jsonMap.get("link"));
        if (jsonMap.containsKey("title")) {
            bannerVO.setTitle(jsonMap.get("title"));
        }
        bannerVO.setImage(jsonMap.get("img"));
        return bannerVO;
    }
}
